<?php
namespace app\api\controller;
use app\common\model\School as SchoolModel;
use app\admin\model\Config;
use think\Db;
use app\common\service\GuguService;


class School extends App
{
    
    public static function NoWhiteList()
    {
        return [
           
            'major_line',
			'before_major_line'
			
        ];
    }
    
    public function index()
    {
        $pagesize = 10;
        $page = $this->request->get("page",1,'intval'); 
        
        $province_id= $this->request->get("province_id",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim'); 
        $school_xingzhi2= $this->request->get("school_xingzhi2",'','trim'); 
        $school_name= $this->request->get("school_name",'','trim'); 
        if(!empty($province_id)){
			$map['province_id'] = ['in',$province_id];
        }
        if(!empty($school_type)){
			//$school_id1 = Db::name('school_type_data')->where('type_id','in',$school_type)->column('school_id');
			$school_id1 = Db::name('school')->where('school_type','in',$school_type)->column('id');
			$map['id'] = ['in',$school_id1];
        }
        if(!empty($school_tese)){
			$school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
			$map['id'] = ['in',$school_id2];
        }
        if(!empty($school_xingzhi)){
			//$school_id3 = Db::name('school_xingzhi_data')->where('xingzhi_id','in',$school_xingzhi)->column('school_id');
			$school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
			$map['id'] = ['in',$school_id3];
        }
		if(isset($school_id1) && isset($school_id2) && isset($school_id3)){
			$school_ids = array_intersect($school_id1,$school_id2,$school_id3);
			$map['id'] = ['in',$school_ids];
		}elseif(isset($school_id1) && isset($school_id2)){
			$school_ids = array_intersect($school_id1,$school_id2);
			$map['id'] = ['in',$school_ids];
		}elseif(isset($school_id1) && isset($school_id3)){
			$school_ids = array_intersect($school_id1,$school_id3);
			$map['id'] = ['in',$school_ids];
		}elseif(isset($school_id2) && isset($school_id3)){
			$school_ids = array_intersect($school_id2,$school_id3);
			$map['id'] = ['in',$school_ids];
		}
		
        if(!empty($school_xingzhi2)){
			$map['school_xingzhi2'] = ['in',$school_xingzhi2];
        }
		
        if(!empty($school_name)){
			$map['college_name'] = ['like','%'.$school_name.'%'];
        }
		//dump(implode(',', array_fill(0, count($school_xingzhi), '%')));die;
		$map['status'] = 1;
        $count = Db::name("school")->where($map)->count();
		$list = Db::name("school")->where($map)->field('id,college_name,cover_image,hot_nums,difficult_nums,province_id,city_id,xian_id,school_suoshu,ranking,school_type,school_xingzhi')->order('ranking asc,id desc')
			->page($page,$pagesize)->select();  
		$suoshu_list = SchoolModel::getSuoshuList();	
		foreach($list as $k=>$v){
			$list[$k]['province'] = Db::name('area')->where('id',$v['province_id'])->value('name');
			$list[$k]['city'] = Db::name('area')->where('id',$v['city_id'])->value('name');
			$list[$k]['district'] = Db::name('area')->where('id',$v['xian_id'])->value('name');
			//$list[$k]['school_type'] = Db::name('school_type_data')->alias('d')->join('school_type t','d.type_id=t.id')->where('d.school_id',$v['id'])->value('t.title');
			$list[$k]['school_type'] = Db::name('school_type')->where('id',$v['school_type'])->value('title');
			//$list[$k]['school_xingzhi'] = Db::name('school_xingzhi_data')->alias('d')->join('school_xingzhi x','d.xingzhi_id=x.id')->where('d.school_id',$v['id'])->value('x.title'); 
			$list[$k]['school_xingzhi'] = Db::name('school_xingzhi')->where('id',$v['school_xingzhi'])->value('title');
			
			$list[$k]['school_suoshu'] = !empty($suoshu_list[$v['school_suoshu']])?$suoshu_list[$v['school_suoshu']]:'';
			$list[$k]['school_tese'] = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id',$v['id'])->column('t.title');
		}
		
        $pages = ceil($count/$pagesize);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);	
		//dump($cate_list);die;
		return $this->show(1,"成功", $data);
		
    }
    
	public function get_province_list()
    {
		$sheng_list = Db::name('area')->field('id,name')->where('pid',0)->order('id asc')->select();
		return $this->show(1,"成功", $sheng_list);
	}
	
	public function get_city_list()
    {
        $province_id = $this->request->get("province_id",0,'intval'); 
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id", '');
        }
		$list = Db::name('area')->where('level',2)->where('pid',$province_id)->field('id,name')->select();
		return $this->show(1,"成功", $list);
	}
	
	public function get_district_list()
    {
        $city_id = $this->request->get("city_id",0,'intval'); 
        if(empty($city_id)){
            return $this->show(2001,"缺少参数city_id", '');
        }
		$list = Db::name('area')->where('level',3)->where('pid',$city_id)->field('id,name')->select();
		return $this->show(1,"成功", $list);
	}
	
	public function get_school_type_list()
    {
		$type_list = Db::name('school_type')->field('id,title')->order('id asc')->select();
		return $this->show(1,"成功", $type_list);
	}
	
	public function get_school_tese_list()
    {
		$tese_list = Db::name('school_tese')->field('id,title')->order('id asc')->select();
		return $this->show(1,"成功", $tese_list);
	}
	public function get_school_xingzhi_list()
    {
		$xingzhi_list = Db::name('school_xingzhi')->field('id,title')->order('id asc')->select();
		$xingzhi_list2 = SchoolModel::getXingzhiList2();
		return $this->show(1,"成功", ['xingzhi_1'=>$xingzhi_list,'xingzhi_2'=>$xingzhi_list2]);
	}
	
    
    public function detail()
    {
        
        $school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
        $info = Db::name("school")->field('id,college_name,cover_image,province_id,city_id,xian_id,school_suoshu,year,shuoshi_count,boshi_count,intro,shizi,school_xingzhi2,img_fengcai,address,call_number,web_site,school_img,school_type,school_xingzhi')->where('id',$school_id)->find();
        if(empty($info)){
            return $this->show(2001,"数据不存在!", '');
        }
		$suoshu_list = SchoolModel::getSuoshuList();
		$xingzhi_list2 = SchoolModel::getXingzhiList2();
		$xingzhi_list2 = array_column($xingzhi_list2,'title','id');
		
		$info['province'] = Db::name('area')->where('id',$info['province_id'])->value('name');
		$info['city'] = Db::name('area')->where('id',$info['city_id'])->value('name');
		$info['district'] = Db::name('area')->where('id',$info['xian_id'])->value('name');
		//$info['school_type'] = Db::name('school_type_data')->alias('d')->join('school_type t','d.type_id=t.id')->where('d.school_id',$info['id'])->value('t.title');
		$info['school_type'] = Db::name('school_type')->where('id',$info['school_type'])->value('title');
			 
		//$info['school_xingzhi'] = Db::name('school_xingzhi_data')->alias('d')->join('school_xingzhi x','d.xingzhi_id=x.id')->where('d.school_id',$info['id'])->value('x.title'); 
		$info['school_xingzhi'] = Db::name('school_xingzhi')->where('id',$info['school_xingzhi'])->value('title');
			
		$info['school_suoshu'] = !empty($suoshu_list[$info['school_suoshu']])?$suoshu_list[$info['school_suoshu']]:'';
		$info['school_tese'] = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id',$info['id'])->column('t.title');
		$info['school_xingzhi2'] = !empty($xingzhi_list2[$info['school_xingzhi2']])?$xingzhi_list2[$info['school_xingzhi2']]:'';
		$img_fengcai = array_filter(explode(',',$info['img_fengcai']));
		foreach($img_fengcai as $kp=>$vp){ 
			$img_fengcai[$kp] = config('app_host').$vp;
		}
		$info['img_fengcai'] = $img_fengcai;
		$info['is_collect'] = 0;
        $user_id = $this->user_id;
		if(!empty($user_id)){
			$flag = Db::name("school_collect")->where('user_id',$user_id)->where('school_id',$school_id)->value('id');
			if(!empty($flag)){
				$info['is_collect'] = 1;
			}
		}
		
		
		return $this->show(1,"成功", $info);
		
    }
     public function detail_extend()
    {
        
        $school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
        $info = Db::name("school")->field('id,college_name,tese_major,pinggu')->where('id',$school_id)->find();
        if(empty($info)){
            return $this->show(2001,"数据不存在!", '');
        }
		
		$info['pinggu'] = json_decode($info['pinggu'],true);
		
		$tese_major = json_decode($info['tese_major'],true);
		//dump($tese_major);
		$info['tese_major'] = array_map(function ($rs){
			foreach($rs["major"] as $k=>$p){ 
				$rs["major"][$k] = ['id'=>$p,'title'=>Db::name("major")->where('id',$p)->value('cate_title')];
			}
			$rs["major_count"] = count($rs["major"]);
            return $rs;
        }, $tese_major);		
		
		
		$yuanxi_list = Db::name('school_major_data')->field('title,major_ids as majors')->where('school_id',$school_id)->select();
		foreach($yuanxi_list as $k=>$p){ 
			$yuanxi_list[$k]['majors'] = Db::name("major")->field('id,cate_title')->where('id','in',$p['majors'])->select();
		}
		$info['yuanxi'] = $yuanxi_list;
		return $this->show(1,"成功", $info);
		
    }
	
	
	public function zhaosheng()
    {
        $pagesize = 10;
        $page = $this->request->get("page",1,'intval'); 
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		
		$title = $this->request->get("title",'','trim'); 
        if(!empty($title)){
            $map['title'] = ['like',"%" . $title . "%"];          
        }
		
		$map['status'] = 1;
		$map['type'] = 1;
		$map['school_id'] = $school_id;
        $count = Db::name("school_article")->where($map)->count();
		$list = Db::name("school_article")->where($map)->field('id,title,views,create_time')->order('id desc')
			->page($page,$pagesize)->select();  
			
		$list = array_map(function ($rs){
            $rs["create_time"] = !empty($rs["create_time"])?date('Y-m-d H:i',$rs["create_time"]):'';
            return $rs;
        }, $list);		
			
        $pages = ceil($count/$pagesize);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"成功", $data);
		
    }
    
    
    public function zhaosheng_detail()
    {
        
        $id = $this->request->get("id",0,'intval'); 
        if(empty($id)){
            return $this->show(2001,"缺少id!", '');
        }
        $info = Db::name("school_article")->field('id,school_id,title,views,writer,content,create_time')->where('id',$id)->where('status',1)->where('type',1)->find();
        if(empty($info)){
            return $this->show(2001,"数据不存在或已下架!", '');
        }
		Db::name("school_article")->where('id',$id)->setInc('views');
		$info["create_time"] = !empty($info["create_time"])?date('Y-m-d H:i',$info["create_time"]):'';
		return $this->show(1,"成功", $info);
		
    }
	public function baogao()
    {
        $pagesize = 10;
        $page = $this->request->get("page",1,'intval'); 
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		
		$map['status'] = 1;
		$map['type'] = 2;
		$map['school_id'] = $school_id;
        $count = Db::name("school_article")->where($map)->count();
		$list = Db::name("school_article")->where($map)->field('id,title,content_type,file_url')->order('id desc')
			->page($page,$pagesize)->select();  
			
		$list = array_map(function ($rs){
            $rs["file_url"] = !empty($rs["file_url"])?$rs["file_url"]:'';
            return $rs;
        }, $list);	
			
        $pages = ceil($count/$pagesize);
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"成功", $data);
		
    }
    
    
    public function baogao_detail()
    {
        
        $id = $this->request->get("id",0,'intval'); 
        if(empty($id)){
            return $this->show(2001,"缺少id!", '');
        }
        $info = Db::name("school_article")->field('id,title,views,writer,content,create_time,content_type')->where('id',$id)->where('status',1)->where('type',2)->find();
        if(empty($info)){
            return $this->show(2001,"数据不存在或已下架!", '');
        }
		if($info['content_type'] == 1){
            return $this->show(2001,"此数据没有详情!", '');
        }
		Db::name("school_article")->where('id',$id)->setInc('views');
		$info["create_time"] = !empty($info["create_time"])?date('Y-m-d H:i',$info["create_time"]):'';
		return $this->show(1,"成功", $info);
		
    }
	
	/*
	//院校录取分数线
	public function college_line()
    {
		$pagesize = 100;
        $page = $this->request->get("page",1,'intval');
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$batch_name = $this->request->get("batch_name",'','trim');
		
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>$pagesize,'searchtype'=>'COLLEGENAME','keyword'=>$college_name,'enrollprovince'=>$enrollprovince,'batchname'=>$batch_name]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
        $pages = ceil($count/$pagesize);
		//dump($list);die;
		$list_new = array_map(function ($rs){
			return ["year"=>$rs['Year'],'title' => $rs["CollegeName"].$rs['SubjectGroup'],'pici'=>$rs['AdmissionBatch'],'selection'=>$rs['CourseSelection'],
					'highest_score'=>$rs["HighestScore"],'lowest_score'=>$rs["LowestScore"],'average_score'=>$rs["AverageScore"],'lowest_rank'=>$rs["LowestRank"],
					];
           
        }, $list);
		
        $data = array('list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"成功", $data);
		
    }
	
	//专业分数线
	public function major_line()
    {
		$pagesize = 100;
        $page = $this->request->get("page",1,'intval');
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
		$type_name = $this->request->get("type_name",'','trim');
		$type_name = ($type_name=='请选择')?'':$type_name;
		$batch_name = $this->request->get("batch_name",'','trim');
		$batch_name = ($batch_name=='请选择')?'':$batch_name;
		
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>$page,'pagesize'=>$pagesize,'enrollprovince'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year),'typename'=>$type_name,'batchname'=>$batch_name]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
        $pages = ceil($count/$pagesize);
		//dump($result);die;
		$list_new = array_map(function ($rs){
			return ["major_name"=>$rs['MajorName'],'batch_name' => $rs["BatchName"],'selection'=>$rs['SubjectSelection'],'high_socre'=>$rs['HighSocre'],'average_score'=>$rs["AverageScore"],
					'lowest_score'=>$rs["LowestScore"],'lowest_section'=>$rs["LowestSection"],'type_name'=>$rs['TypeName']
					];
           
        }, $list);
		
		$year_list = [];
		for($i=1;$i<11;$i++){
			$year_list[] = date('Y',strtotime("-$i year"));
		}
		$batch_list = array_unique(array_column($list_new,'batch_name'));
		array_unshift($batch_list,'请选择');
		//dump($batch_list);die;
		$type_list = array_unique(array_column($list_new,'type_name'));
		array_unshift($type_list,'请选择');
		
        $data = array('major_data'=>['list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize],'year_list'=>$year_list,'batch_list'=>$batch_list,'type_list'=>$type_list);
		return $this->show(1,"成功", $data);
		
    }
	
	//提前批分数线
	public function before_major_line()
    {
		$pagesize = 100;
        $page = $this->request->get("page",1,'intval');
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
		$type_name = $this->request->get("type_name",'','trim');
		$type_name = ($type_name=='请选择')?'':$type_name;
		$batch_name = '本科提前批B段';
		
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>$page,'pagesize'=>$pagesize,'enrollprovince'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year),'typename'=>$type_name,'batchname'=>$batch_name]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
        $pages = ceil($count/$pagesize);
		//dump($result);die;
		$list_new = array_map(function ($rs){
			return ["major_name"=>$rs['MajorName'],'batch_name' => $rs["BatchName"],'selection'=>$rs['SubjectSelection'],'high_socre'=>$rs['HighSocre'],'average_score'=>$rs["AverageScore"],
					'lowest_score'=>$rs["LowestScore"],'lowest_section'=>$rs["LowestSection"],'type_name'=>$rs['TypeName']
					];
           
        }, $list);
		
		$year_list = [];
		for($i=1;$i<11;$i++){
			$year_list[] = date('Y',strtotime("-$i year"));
		}
		$type_list = array_unique(array_column($list_new,'type_name'));
		array_unshift($type_list,'请选择');
		
        $data = array('major_data'=>['list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize],'year_list'=>$year_list,'type_list'=>$type_list);
		return $this->show(1,"成功", $data);
		
    }*/
	
	public function get_college_condition()
    {
		
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>1,'pagesize'=>100,'searchtype'=>'COLLEGENAME','keyword'=>$college_name,'enrollprovince'=>$enrollprovince]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		if($count>100){
			$result2 = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>2,'pagesize'=>100,'searchtype'=>'COLLEGENAME','keyword'=>$college_name,'enrollprovince'=>$enrollprovince]);
			if($result2[0] != 200){
				return $this->show(2002,$result2[1]??'error', '');
			}
			$list2 = $result2[1][1];
			$list = array_merge($list,$list2);
		}
		$type_list = array_values(array_unique(array_column($list,'TypeName')));
		
        $data = array('type_list'=>$type_list);
		return $this->show(1,"成功", $data);
		
    }
	
	//院校录取分数线
	public function college_line()
    {
		$pagesize = 100;
        $page = $this->request->get("page",1,'intval');
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$type_name = $this->request->get("type_name",'','trim');
		
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>$pagesize,'searchtype'=>'COLLEGENAME','keyword'=>$college_name,'enrollprovince'=>$enrollprovince,'type'=>$type_name]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
        $pages = ceil($count/$pagesize);
		//dump($list);die;
		$list_new = array_map(function ($rs){
			return ["year"=>$rs['Year'],'title' => $rs["CollegeName"].$rs['SubjectGroup'],'pici'=>$rs['AdmissionBatch'],'selection'=>$rs['CourseSelection'],
					'highest_score'=>$rs["HighestScore"],'lowest_score'=>$rs["LowestScore"],'average_score'=>$rs["AverageScore"],'lowest_rank'=>$rs["LowestRank"],'type_name'=>$rs["TypeName"]
					];
           
        }, $list);
		
        $data = array('list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);
		return $this->show(1,"成功", $data);
		
    }
	
	public function get_major_condition(){
		
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year)]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		if($count>100){
			$result2 = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>2,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year)]);
			if($result2[0] != 200){
				return $this->show(2002,$result2[1]??'error', '');
			}
			$list2 = $result2[1][1];
			$list = array_merge($list,$list2);
		}
		
		
		$year_list = [];
		for($i=1;$i<7;$i++){
			$year_list[] = date('Y',strtotime("-$i year"));
		}
		
		$batch_list = array_values(array_unique(array_column($list,'BatchName')));
		//array_unshift($batch_list,'请选择');
		//dump($list);die;
		$type_list = array_values(array_unique(array_column($list,'TypeName')));
		//array_unshift($type_list,'请选择');
		
		$data = array('year_list'=>$year_list,'batch_list'=>$batch_list,'type_list'=>$type_list);
		return $this->show(1,"成功", $data);
	}
	
	//专业分数线
	public function major_line()
    {
		$pagesize = 100;
        $page = $this->request->get("page",1,'intval');
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
		$type_name = $this->request->get("type_name",'','trim');
        if(empty($type_name)){
            //return $this->show(2001,"缺少参数type_name!", '');
        }
		$batch_name = $this->request->get("batch_name",'','trim');
        if(empty($batch_name)){
            //return $this->show(2001,"缺少参数batch_name!", '');
        }
		
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>$page,'pagesize'=>$pagesize,'enrollprovince'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year),'typename'=>$type_name,'batchname'=>$batch_name]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
        $pages = ceil($count/$pagesize);
		//dump($result);die;
		$list_new = array_map(function ($rs){
			return ["major_name"=>$rs['MajorName'],'batch_name' => $rs["BatchName"],'selection'=>$rs['SubjectSelection'],'high_socre'=>$rs['HighSocre'],'average_score'=>$rs["AverageScore"],
					'lowest_score'=>$rs["LowestScore"],'lowest_section'=>$rs["LowestSection"],'type_name'=>$rs['TypeName']
					];
           
        }, $list);
		
        $data = ['list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize];
		return $this->show(1,"成功", $data);
		
    }
	
	//获取招生计划筛选条件
	public function get_plan_condition(){
		
		$pagesize = 20;
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>1,'pagesize'=>$pagesize,'provincename'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year)]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		if($count>$pagesize){
			$result2 = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>2,'pagesize'=>$pagesize,'provincename'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year)]);
			if($result2[0] != 200){
				return $this->show(2002,$result2[1]??'error', '');
			}
			$list2 = $result2[1][1];
			$list = array_merge($list,$list2);
		}
		
		
		$year_list = [];
		for($i=1;$i<4;$i++){
			$year_list[] = date('Y',strtotime("-$i year"));
		}
		
		$batch_list = array_values(array_unique(array_column($list,'BatchName')));
		//array_unshift($batch_list,'请选择');
		//dump($list);die;
		$type_list = array_values(array_unique(array_column($list,'Type')));
		//array_unshift($type_list,'请选择');
		
		$data = array('year_list'=>$year_list,'batch_list'=>$batch_list,'type_list'=>$type_list);
		return $this->show(1,"成功", $data);
	}
	//招生计划
	public function plan()
    {
		$pagesize = 20;
        $page = $this->request->get("page",1,'intval');
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
		$type_name = $this->request->get("type_name",'','trim');
        if(empty($type_name)){
            //return $this->show(2001,"缺少参数type_name!", '');
        }
		$batch_name = $this->request->get("batch_name",'','trim');
        if(empty($batch_name)){
            //return $this->show(2001,"缺少参数batch_name!", '');
        }
		
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>$page,'pagesize'=>$pagesize,'provincename'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year),'type'=>$type_name,'batchname'=>$batch_name]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
        $pages = ceil($count/$pagesize);
		//dump($result);die;
		$list_new = array_map(function ($rs){
			return ["major_name"=>$rs['CollegeMajorName'],'batch_name' => $rs["BatchName"],'selection'=>$rs['CourseSelectionRequirements'],'people_nums'=>$rs['EnrollmentNumbers'],'xuezhi'=>$rs["InSchoolYears"]
					];
           
        }, $list);
		
        $data = ['list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize];
		return $this->show(1,"成功", $data);
		
    }
	
	
	//院校详情-提前批招生计划-筛选条件
	public function get_tiqian_plan_condition(){
		
		$year_list = [];
		for($i=1;$i<7;$i++){
			$year_list[] = date('Y',strtotime("-$i year"));
		}
		
		$data = array('year_list'=>$year_list);
		return $this->show(1,"成功", $data);
	}
	
	//院校详情-提前批招生计划
	public function tiqian_plan()
    {
		$pagesize = 50;
        $page = $this->request->get("page",1,'intval');
		$province_id = $this->province_id;
		$user_id = $this->user_id;
		
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		//$batch_name = '本科提前批C段';
		$batch_name = SchoolModel::getTiqianBtachs();
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
        
		$result = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>$page,'pagesize'=>$pagesize,'provincename'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year),'batchname'=>$batch_name]);
		//dump($result);die;
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
        $pages = ceil($count/$pagesize);
		//dump($result);die;
		$list_new = array_map(function ($rs){
			return ["major_name"=>$rs['CollegeMajorName'],'batch_name' => $rs["BatchName"],'selection'=>$rs['CourseSelectionRequirements'],'people_nums'=>$rs['EnrollmentNumbers'],'xuezhi'=>$rs["InSchoolYears"]
					];
        }, $list);
		
        $data = ['list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize];
		return $this->show(1,"成功", $data);
		
    }
	
	//院校详情-提前批分数线-筛选条件
	public function get_before_major_condition(){
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
		//$batch_name = '本科提前批B段';
		$batch_name = SchoolModel::getTiqianBtachs();
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year),'batchname'=>$batch_name]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		if($count>100){
			$result2 = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>2,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year),'batchname'=>$batch_name]);
			if($result2[0] != 200){
				return $this->show(2002,$result2[1]??'error', '');
			}
			$list2 = $result2[1][1];
			$list = array_merge($list,$list2);
		}
		
		$year_list = [];
		for($i=1;$i<7;$i++){
			$year_list[] = date('Y',strtotime("-$i year"));
		}
		
		$type_list = array_values(array_unique(array_column($list,'TypeName')));
		
		$data = array('year_list'=>$year_list,'type_list'=>$type_list);
		return $this->show(1,"成功", $data);
	}
	
	//院校详情-提前批分数线
	public function before_major_line()
    {
		$pagesize = 100;
        $page = $this->request->get("page",1,'intval');
		$school_id = $this->request->get("school_id",0,'intval'); 
        if(empty($school_id)){
            return $this->show(2001,"缺少参数school_id!", '');
        }
		$province_id = $this->province_id;
        if(empty($province_id)){
            return $this->show(2001,"缺少参数province_id!", '');
        }
		
		$year = $this->request->get("year",0,'intval');
		if(empty($year)){
			$year = date('Y',strtotime('-1 year'));
		}
		$type_name = $this->request->get("type_name",'','trim');
		$type_name = ($type_name=='请选择')?'':$type_name;
		//$batch_name = '本科提前批,提前批,本科提前批A段,专科提前批,本科提前批B段,普通类提前批';//本科提前批|本科提前批A段|专科提前批|本科提前批B段|提前批|普通类提前批
		$batch_name = SchoolModel::getTiqianBtachs();
		
		$college_name = Db::name("school")->where('id',$school_id)->value('college_name');
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>$page,'pagesize'=>$pagesize,'enrollprovince'=>$enrollprovince,'schoolname'=>$college_name,'year'=>intval($year),'typename'=>$type_name,'batchname'=>$batch_name]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
        $pages = ceil($count/$pagesize);
		//dump($result);die;
		$list_new = array_map(function ($rs){
			return ["major_name"=>$rs['MajorName'],'batch_name' => $rs["BatchName"],'selection'=>$rs['SubjectSelection'],'high_socre'=>$rs['HighSocre'],'average_score'=>$rs["AverageScore"],
					'lowest_score'=>$rs["LowestScore"],'lowest_section'=>$rs["LowestSection"],'type_name'=>$rs['TypeName']
					];
           
        }, $list);
		
		
        $data = ['list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize];
		return $this->show(1,"成功", $data);
		
    }
	
	public function hot_ranking(){
		$type = $this->request->get("type",1,'intval'); 
		$list = Db::name("school")->field('id,college_name,hot_nums')->where('school_xingzhi2',$type)->order('hot_nums desc,ranking asc')->limit(10)->select();
		
		return $this->show(1,"成功", $list);
	}
	
	
	
}